import { resourceEntApi, resourceLibraryApi } from '@/api';
import { useEffect, useState } from 'react';
// import DomRender from './DomRender';
import ExaminationItem from '@/components/resourceLibraryComp/TestPaperDetail/ExaminationItem';
import OStyle from '../TestPaperDetail/index.less';

function ExaminationDetail(props: { examinationId: string }) {
  const { examinationId } = props;
  const [examinationList, setExaminationList] = useState<any[]>([]);
  useEffect(() => {
    if (process.env.processEnvDetail.REACT_APP_PLATFORM === 'boss') {
      resourceLibraryApi.getExaminationById({ questionId: examinationId }).then((res: any) => {
        console.log('--Examination--res--:', res);
        const {
          data: { content, anwserItems, selectItems },
        } = res;
        let selectItemList: any[] = [];
        let anwserItemList: any[] = [];
        try {
          selectItemList = JSON.parse(selectItems);
          anwserItemList = JSON.parse(anwserItems);
        } catch (err) {
          console.log('---Examination--jsonParse--err--:', err);
        }
        const tempExaminationList = [{ content, selectItemList, anwserItemList }];
        setExaminationList(tempExaminationList);
      });
    } else {
      resourceEntApi.getExaminationById({ questionId: examinationId }).then((res: any) => {
        const {
          data: { content, answerList, selectItemDtoList },
        } = res;
        let selectItemList: any[] = [];
        let anwserItemList: any[] = [];
        try {
          selectItemList = selectItemDtoList;
          anwserItemList = answerList;
        } catch (err) {
          console.log('---Examination--jsonParse--err--:', err);
        }
        const tempExaminationList = [{ content, selectItemList, anwserItemList }];
        setExaminationList(tempExaminationList);
      });
    }
  }, []);
  return (
    // <div>
    //   {examinationList.map((listItem: { content: string; selectItemList: any[]; anwserItems: string }, index) => (
    //     <DomRender
    //       key={index}
    //       questionId={examinationId}
    //       content={listItem.content}
    //       selectItemList={listItem.selectItemList}
    //       anwserItems={listItem.anwserItems}
    //     />
    //   ))}
    // </div>
    <div className={OStyle.item_exa_list}>
      {examinationList.map((queItem: any, queIndex: number) => (
        <ExaminationItem key={queIndex} queIndex={queIndex} queItem={queItem} />
      ))}
    </div>
  );
}

export default ExaminationDetail;
